<pre><?
//You need to have all skills locally stored for this to properly work
define('GWBBCODE_ROOT', '..');
require_once(GWBBCODE_ROOT.'/constants.inc.php');

//Load skill database
$skills = require(SKILLS_PATH_1);  //Can't use array_merge here otherwise keys get lost
$add_list = require(SKILLS_PATH_2);
foreach ($add_list as $key => $val) {
   $skills[$key] = $val;
}

//Order database the same way as in the game
$attribute_order = array ('Air Magic', 'Axe Mastery', 'Beast Mastery', 'Blood Magic', 'Channeling Magic', 'Command', 'Communing', 'Critical Strikes', 'Curses', 'Dagger Mastery', 'Deadly Arts', 'Death Magic', 'Divine Favor', 'Domination Magic', 'Earth Magic', 'Earth Prayers', 'Energy Storage', 'Expertise', 'Fast Casting', 'Fire Magic', 'Hammer Mastery', 'Healing Prayers', 'Illusion Magic', 'Inspiration Magic', 'Leadership', 'Marksmanship', 'Motivation', 'Mysticism', 'Protection Prayers', 'Restoration Magic', 'Scythe Mastery', 'Shadow Arts', 'Smiting Prayers', 'Soul Reaping', 'Spawning Power', 'Spear Mastery', 'Strength', 'Swordsmanship', 'Tactics', 'Water Magic', 'Wilderness Survival', 'Wind Prayers', 'Asura rank', 'Deldrimor rank', 'Ebon Vanguard rank', 'Kurzick rank', 'Luxon rank', 'Lightbringer rank', 'Norn rank', 'Sunspear rank', 'No Attribute');
$profession_order = Array('Warrior', 'Ranger', 'Monk', 'Necromancer', 'Mesmer', 'Elementalist', 'Assassin', 'Ritualist', 'Paragon', 'Dervish', 'No profession');
uasort($skills, 'sort_function');
function sort_function($a, $b) {
   global $profession_order, $attribute_order;

   if ($a['pve_only'] < $b['pve_only'])
      return -1;
   else if ($a['pve_only'] > $b['pve_only'])
      return 1;

   $profA = array_search($a['profession'], $profession_order);
   $profB = array_search($b['profession'], $profession_order);
   if ($profA < $profB)
      return -1;
   else if ($profA > $profB)
      return 1;

   $attrA = array_search($a['attribute'], $attribute_order);
   $attrB = array_search($b['attribute'], $attribute_order);
   if ($attrA < $attrB)
      return -1;
   else if ($attrA > $attrB)
      return 1;

   if ($a['name'] < $b['name'])
      return -1;
   else if ($a['name'] > $b['name'])
      return 1;
      
   return 0;
}

//Extract EotN skills
$eotn_skills = Array();
foreach ($skills as $id => $skill) {
   if ($skill['chapter'] == 4) {
      $eotn_skills[$id] = $skill;
   }
}

//Output EotN skills
$cur_prof = false;
$cur_attr = false;
$first_prof = true;
foreach($eotn_skills as $id => $skill) {
   //PvP skills
   if ($skill['pve_only'] == 0) {
      if ($cur_prof != $skill['prof']) {
         if (!$first_prof) {
            echo "[/build]\n";
         }
         else {
            $first_prof = false;
         }
         echo "[build prof={$skill['profession']} name=\"{$skill['profession']}\"";
         if ($skill['profession'] == 'Monk') {
            echo ' div=10';
         }
         if ($skill['profession'] == 'Ritualist') {
            echo ' spawn=10';
         }
         echo ']';
         $cur_prof = $skill['prof'];
         $cur_attr = $skill['attr'];
      }
      else if ($cur_attr != $skill['attr']) {
         echo '-';
         $cur_attr = $skill['attr'];
      }
   }
   //PvE skills
   else {
      if ($cur_attr != $skill['attr']) {
         if (!$first_prof) {
            echo "[/build]\n";
         }
         else {
            $first_prof = false;
         }
         echo "[build prof=? name=\"{$skill['attribute']}\"]";
         $cur_attr = $skill['attr'];
      }
   }
   echo '['.$skill['name'].']';
}
echo "[/build]\n";
?></pre>